package io.gitee.zhucan123.core.infrastructure.exception.advice;

import com.niimbot.middlend.core.infrastructure.exception.InternalException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 录服务器内部处理异常（例如调用第三方接口失败）
 *
 * @author guodu
 * @date 2019/11/27
 */
@RestControllerAdvice
public class InternalExceptionAdvice {

  @ExceptionHandler(InternalException.class)
  @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE)
  public ErrorDTO handlerInternalError(HttpServletRequest request, InternalException e) {
    String errorURL = request.getRequestURL().toString();
    return new ErrorDTO(e.getMessage(), HttpStatus.NOT_IMPLEMENTED.value(), errorURL);
  }

}
